package zajinhua;

import java.util.ArrayList;

public class OneCardSet {
	ArrayList<Card> haitaoSet = new ArrayList<Card>();
	ArrayList<Card> hongtaoSet = new ArrayList<Card>();
	ArrayList<Card> fangkuaiSet = new ArrayList<Card>();
	ArrayList<Card> meihuaSet = new ArrayList<Card>();

	public OneCardSet() {
		int value;
		for (int i = 1; i < 14; i++) {
			value = (int) (Math.random() * 13) + 1;
			//System.out.println(" " + value);
			boolean canAdd = true;
			for (int m = 0; m < this.haitaoSet.size(); m++) {
				if (value == this.haitaoSet.get(m).getNum()) {
					canAdd = false;
					i--;
					break;
				}
			}
			if (canAdd) {
				this.haitaoSet.add(new Card(Pattern.HEITAO, value));
			}
		}

		for (int i = 1; i < 14; i++) {
			value = (int) (Math.random() * 13) + 1;
			//System.out.println(" " + value);
			boolean canAdd = true;
			for (int m = 0; m < this.hongtaoSet.size(); m++) {
				if (value == this.hongtaoSet.get(m).getNum()) {
					canAdd = false;
					i--;
					break;
				}
			}
			if (canAdd) {
				this.hongtaoSet.add(new Card(Pattern.HEITAO, value));
			}
		}
		for (int i = 1; i < 14; i++) {
			value = (int) (Math.random() * 13) + 1;
			//System.out.println(" " + value);
			boolean canAdd = true;
			for (int m = 0; m < this.fangkuaiSet.size(); m++) {
				if (value == this.fangkuaiSet.get(m).getNum()) {
					canAdd = false;
					i--;
					break;
				}
			}
			if (canAdd) {
				this.fangkuaiSet.add(new Card(Pattern.HEITAO, value));
			}
		}
		for (int i = 1; i < 14; i++) {
			value = (int) (Math.random() * 13) + 1;
			//System.out.println(" " + value);
			boolean canAdd = true;
			for (int m = 0; m < this.meihuaSet.size(); m++) {
				if (value == this.meihuaSet.get(m).getNum()) {
					canAdd = false;
					i--;
					break;
				}
			}
			if (canAdd) {
				this.meihuaSet.add(new Card(Pattern.HEITAO, value));
			}
		}
	}

	public Card giveCard() {
		int i = (int) (Math.random() * 4);
		ArrayList<Card> chooseList = null;
		switch (i) {
		case 0:
			chooseList = this.haitaoSet;
			break;
		case 1:
			chooseList = this.haitaoSet;
			break;
		case 2:
			chooseList = this.fangkuaiSet;
			break;
		case 3:
			chooseList = this.meihuaSet;
			break;
		default:
			System.out.println("Sorry error");
			break;
		}
		Pattern p=chooseList.get(0).getPattern();
		Card cardGiven = new Card(chooseList.get(0).getPattern(), chooseList
				.get(0).getNum());
		chooseList.remove(0);
		return cardGiven;
	}
}
